package com.zuoshen_algorithm;

/**
 * 项目名称: java_algorithm
 * @ClassName MatrixPrinting 矩形打印
 * @Description
 * @Author huipanxing huipanxing@chinasofti.com   @Date 2022/2/28 14:06
 */
public class MatrixPrinting {


    public static void main(String[] args) {
        int[][] array = new int[][]{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
        System.out.println("原始数组打印：");
        Util.printArray(array);
        System.out.println("处理之后打印：");
        int a = 0;
        int b = 0;
        int c = array.length - 1;
        int d = array[0].length - 1;
        while (a <= c && b <= d) {
            matrix(array, a++, b++, c--, d--);
        }
    }

    /**
     * 功能描述: 矩阵打印
     * @author huipanxing huipanxing@chinasofti.com
     * @date 2022/2/28 14:18
     * @param array
     * @param a 左上角的行坐标
     * @param b 左上角的列坐标
     * @param c 右下角的行坐标
     * @param d 右下角的列坐标
     * @return void
     */
    private static void matrix(int[][] array, int a, int b, int c, int d) {

        for (int i = b; i < d; i++) {
            System.out.print(array[a][i]+"\t");
        }
        for (int i = a; i < c; i++) {
            System.out.print(array[i][d]+"\t");
        }
        for (int i = d; i > b; i--) {
            System.out.print(array[c][i]+"\t");
        }
        for (int i = c; i > a; i--) {
            System.out.print(array[i][a]+"\t");
        }
    }
}
